import sqlite3

##连接数据库
conn = sqlite3.connect('test.db')
## 创建游标
cursor = conn.cursor()
# 创建表
cursor.execute("create table if not exists user (id integer(11) primary key, name varchar(20))")

##insert data
sql = "insert into user values (1, 'root')"
sql2 = "insert into user values (?, ?)"
cursor.executemany(sql2, [(2, 'admin')])
conn.commit()##提交更改，事务


##查询
sql = "select * from user"
cursor.execute(sql)
for row in cursor:print(row[1])

results = cursor.fetchall()
for row in results:
    print(row[1])